<template>
	<view class="box">
		<view class="hiddenTitle">
		</view>
		<view class="cu-bar bg-white">
			<view class="action">
				<button class="cu-btn cuIcon-sort margin-right-sm" @tap="showModal" data-target="DrawerModalL"></button>
				<view class="action" v-if="authority != '[ROLE_USER]' && authority!= ''">
					<view class="action" @tap="toUpdateMeeting" v-if="authority != '[ROLE_ADMIN]'">
						<text class="text-gray"
							:class="{'cuIcon-write':sWriteIcon,'cuIcon-writefill':WriteIcon}"></text>
					</view>
					<view class="action" @tap="toAddMeeting">
						<text class="iconSize text-gray"
							:class="{'cuIcon-roundadd':sAddIcon,'cuIcon-roundaddfill':AddIcon}"></text>
					</view>
				</view>
			</view>
			<view class="content text-blod">
				会议记录
			</view>



		</view>
		<view class="cu-modal drawer-modal justify-start" :class="modalName=='DrawerModalL'?'show':''" @tap="hideModal">
			<view class="cu-dialog basis-lg padding-top-lg" @tap.stop=""
				:style="[{top:CustomBar+'px',height:'calc(100vh - ' + CustomBar + 'px)'}]">
				<view class="cu-list menu text-left">
					<view class="cu-item arrow" v-for="(term,index) in terms" :key="term.id"
						:class="isactive == index ? 'test-grey':'' " @click="selectTerm(term.data, index)">
						<view class="cu-item" :class="menuArrow?'arrow':''">
							<view class="content">
								<text>{{term.data}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		props: {
			reciveMeetings: {}
		},
		data() {
			return {
				serverUrl: this.$globalUrl,
				CustomBar: this.CustomBar,
				isactive: -1,
				modalName: null,
				authority: uni.getStorageSync('authority'),
				terms: [{
						id: 0,
						data: '2021-2022 第一学期',
					},
					{
						id: 1,
						data: '2021-2022 第二学期',
					},
					{
						id: 2,
						data: '2022-2023 第一学期',
					},
					{
						id: 3,
						data: '2022-2023 第二学期',
					},
				],
				sWriteIcon: true,
				WriteIcon: false,
				sAddIcon: true,
				AddIcon: false,
        isSelected: false
			}
		},
		onShow() {
			this.sWriteIcon = true;
		},
		onLoad() {

		},
		methods: {
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			RadioChange(e) {
				this.radio = e.detail.value
			},

			selectTerm(res, index) {
				let self = this;
				console.log(res);
				var term = res;
				this.isactive = index;
        self.isSelected = true
        this.$emit('changeSelect', this.isSelected)
				setTimeout(function() {
					self.hideModal()
				}, 250);
				uni.request({
						url: self.serverUrl + '/meet/getMeetingInfo',
						data: {
							term: term,
							week: 1
						},
						header: {
							"Authorization": uni.getStorageSync('tokenHead') + ' ' + uni.getStorageSync('token')
						}
					})
					.then(data => {
						var [error, res] = data;
						if (res.data.code == 200) {
							var meeting = res.data.object;
							self.meetings = meeting[0];
							this.$emit("getMeetings", self.meetings);
							this.$emit("getTerm", term)
						} else {
							wx.showToast({
								title: '获取信息失败了鸭',
								icon: 'error',
								duration: 2000
							})
						}
					})
			},
			toAddMeeting() {
				if (this.sAddIcon == true) {
					this.sAddIcon = false;
					this.AddIcon = true;
				} else {
					this.sAddIcon = true;
					this.AddIcon = false;
				}


				uni.navigateTo({
					url: '../../subpkg/insertMeeting/insertMeeting'
				});
			},
			toUpdateMeeting() {
				if (this.sWriteIcon == true) {
					this.sWriteIcon = false;
					this.WriteIcon = true;
				} else {
					this.sWriteIcon = true;
					this.WriteIcon = false;
				}
				let meetings = this.reciveMeetings;
				uni.navigateTo({
					url: '../../subpkg/updateMeeting/updateMeeting?meetings=' + JSON.stringify(meetings)
				});
				console.log(meetings)
			}
		}
	}
</script>

<style>
	.test-grey {
		color: #8799a3;
	}

	.hiddenTitle {
		height: 35px;
		background-color: #FFFFFF;
	}

	.iconSize {
		margin-left: 20rpx;
	}
</style>
